<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <title>拾光&nbsp;•&nbsp;失物招领</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection"content="telephone=no, email=no" />
    <meta name="renderer" content="webkit">

    <meta name="title" content="拾光&nbsp;•&nbsp;失物招领" />
    <meta name="img" content="http://source.timepicker.cn/uploads/default/laf.png-120" />
    <meta name="description" content="不管是捡了东西还是丢了东西都来这里看看吧" />
    
    <!--icon-->
    <link rel="shortcut icon" href="http://source.timepicker.cn/uploads/default/laf.png-120" />
    <!--拾光css-->
    <link rel="stylesheet" href="http://source.timepicker.cn/static/css/ptime_v0.4.min.css">
    <!-- 小应用css -->
    <link rel="stylesheet" href="/css/style.css">
    <!-- animate css -->
    <link rel="stylesheet" href="http://source.timepicker.cn/static/css/animate.min.css">
    <!--主题css-->
    <style type="text/css">
      a{color: #333;}   /* 未访问的链接 */
      .active{color:#a8c0d8 !important; border-color: #a8c0d8 !important;}
      nav ul li a.current{color: #a8c0d8;border-color: #a8c0d8;}
      .mcolor{color: #a8c0d8;}
      .bg-mcolor{background-color: #a8c0d8 !important;}
      .button.mcolor{border-color:#a8c0d8;}
      .button.mcolor.active{background-color: #a8c0d8;}
      .label.current{background-color: #a8c0d8;}
      #top-a{background-color: #a8c0d8;}
    </style>
</head>

<body class="agent-{{ua}}">
    <!--头部-->
    <header class="bg-mcolor fixed top" >
        <h1>拾光&nbsp;•&nbsp;失物招领</h1>
        <span class="button top-right white" onclick="share()">分享</span>
    </header>
    <!--其他区域-->
    <section>
      <div class="info-container border-bottom" style="padding-bottom: 0;">
        {{#if result.prepublish}}
          <p class="warn-container">先搜索，比直接发布信息更高效</p>
          <br>
        {{/if}}
        <p><span class="red">* </span>丢了还是捡了？</p>
        <input type="radio" name="laf" class="radio" value="0"> 丢了
        <input type="radio" name="laf" class="radio" value="1"> 捡了
        <br><br>
        <p><span class="red">* </span>选择相关标签</p>
        {{#each result.list}}
          <span class="tag tag-normal" id="{{_id}}">{{name}}</span>
        {{/each}}
        <br><br><br><br>
        <a id="search" class="right filled-button">搜索</a>
        {{#if result.prepublish}}
          <a id="publish" class="right filled-button">发布</a>
        {{/if}}
        <p style="margin-bottom: 0; margin-top: .5rem;">搜索结果</p>
        <hr>
      </div>
    </section>
    <!-- 分享 -->
    <div id="share-box">
     <div id="share-top-box">
        <h4>分享至：</h4>   
        <div class="bdsharebuttonbox">
          <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
          <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
          <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
        </div>
     </div>
    </div>
    <div id="toast-box" ></div>
    <!--拾光js-->
    <script type="text/javascript" src="http://source.timepicker.cn/static/js/ptime_v0.4.min.js"></script>
    <script type="text/javascript">
      // 网页分享
      if ('{{ua}}' == 'other') {
        var img_url = '';
        if ($('meta[name="img"]')[0].content) {
            img_url = $('meta[name="img"]')[0].content;
        }else{
            img_url = typeof($('img')[0])!='undefined'?$('img')[0].src:$('link[rel="shortcut icon"]')[0].href;
        };
        window._bd_share_config = {
            common : {
                bdText : $('meta[name="title"]')[0].content, 
                bdDesc : $('meta[name="description"]')[0].content, 
                bdUrl  : window.location.href,   
                bdPic  : img_url
            },
            share : [{
                "bdSize" : 24
            }]
        }
        with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
      }
    </script>

    <script type="text/javascript" src="/js/index.js"></script>

    <script type="text/javascript">
      var token = '{{result.token}}'
      var type = '{{result.type}}'

      var tags = {}
      $('.tag').on(getListenEvent(), function (e) {
        if (!$(this).prehandler.handler(e)) return;
        if ($(this).hasClass('tag-normal')) {
          $(this).removeClass('tag-normal').addClass('tag-filled')
          tags[$(this).attr('id')] = true
        } else {
          $(this).removeClass('tag-filled').addClass('tag-normal')
          delete tags[$(this).attr('id')]
        }
      })

      $('#search').on(getListenEvent(), function(e) {
        if (!$(this).prehandler.handler(e)) return;

        if ($("input[name='laf']:checked").length == 0) {
          toast('请填写您丢了，还是捡了东西')
          return
        }

        if (Object.keys(tags).length == 0) {
          toast('至少选择一个tag')
          return;
        }
        $('.lafitem').remove()
        $.ajax({
          url: '/laf/tag',
          type: 'post',
          data: {
            tags: JSON.stringify(Object.keys(tags)),
            type: Number($("input[name='laf']:checked").val())
          },
          success: function (data) {
            if (data.error > 0) {
              toast(data.message);
              return;
            } else {
              // console.log(data.result)
              data.result.list.forEach(function (laf) {
                $('section').append(buildLafItem(laf, '{{isApp}}', '{{ua}}', '{{token}}'))
              })
            }
          },
          error: function (data) {
            toast('程序员正在打瞌睡，打个电话给他？');
          }
        })
      })

      $('#publish').on(getListenEvent(), function(e) {
        if (!$(this).prehandler.handler(e)) return;
        if (Object.keys(tags).length == 0) {
          toast('至少选择一个tag, 然后再发布信息')
          return;
        }
        location.href = '/laf/addPage?prepublish={{result.prepublish}}&type=' + $("input[name='laf']:checked").val() + '&selectedTags=' + encodeURIComponent(Object.keys(tags))
      })

    </script>
</body>
</html>